package com.example.demo.controller;


import com.example.demo.entity.Course;
import com.example.demo.service.ICourseService;
import com.example.demo.utils.AjaxJson;
import com.example.demo.vo.courseSelectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 课程表 前端控制器
 * </p>
 *
 * @author 
 * @since 2025-11-10
 */
@RestController
@RequestMapping("/course")
public class CourseController {
    
    @Autowired
    private ICourseService courseService;
    //TODO 要修改上关联表切断和班级与老师的关联

    @RequestMapping("/add")
    public AjaxJson add(@RequestBody Course course) {
        return courseService.save(course) ? AjaxJson.getSuccess("添加成功") : AjaxJson.getError("添加失败");
    }
    
    @RequestMapping("/delete")
    public AjaxJson delete(@RequestParam Integer id) {
        return courseService.removeById(id) ? AjaxJson.getSuccess("删除成功") : AjaxJson.getError("删除失败");
    }
    
    @RequestMapping("/update")
    public AjaxJson update(@RequestBody Course course) {
        return courseService.updateById(course) ? AjaxJson.getSuccess("修改成功") : AjaxJson.getError("修改失败");
    }
    
    @RequestMapping("/query")
    public AjaxJson query() {
        List<courseSelectVo> vo=courseService.queryE();

        return AjaxJson.getPageData((long)vo.size(),vo);
    }

    //TODO 给添加课程使用，需要做教师教授关联表查询的约束，但没做，算了
    @RequestMapping("/query/all")
    public AjaxJson queryAll() {
        return AjaxJson.getSuccessData(courseService.list());
    }

    @RequestMapping("/query/id")
    public AjaxJson query(@RequestParam Integer id) {
        return AjaxJson.getSuccessData(courseService.getById(id));
    }
}